﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RMS.EF.Model
{
    [MetadataType(typeof(Demo_User_Metadata))]
    public partial class Demo_User
    {

        [Range(1, 199, ErrorMessage = "年龄范围在1-199")]//大小范围
        [DataType(DataType.Text)]
        [RegularExpression(@"^-?\d+$", ErrorMessage = "年龄只能输入整数")]//正则表达式验证
        [NotMapped]
        public int? Age { get; set; }

        [Required(AllowEmptyStrings = false, ErrorMessage = "请再次输入密码")]
        [Compare("Password", ErrorMessage = "输入密码与原密码不同")]//比较两个字段相同
        [NotMapped]
        public string RePassword { get; set; }

        /// <summary>
        /// 删除状态
        /// </summary>
        [NotMapped]
        public E_Deleted EDeleted
        {
            get
            {
                if (!this.Deleted.HasValue)
                {
                    this.Deleted = (int)E_Deleted.Normal;
                }
                return (E_Deleted)this.Deleted.Value;
            }
            set
            {
                this.Deleted = (int)value;
            }
        }
        /// <summary>
        /// 是否可用
        /// </summary>
        [NotMapped]
        public E_Status EStatus
        {
            get
            {
                if (!this.Status.HasValue)
                {
                    this.Status = (int)E_Status.Disable;
                }
                return (E_Status)this.Status.Value;
            }
            set
            {
                this.Status = (int)value;
            }
        }
    }  

    internal class Demo_User_Metadata
    {
        [Required(AllowEmptyStrings = false, ErrorMessage = "请输入用户名")]//必填
        public string UserName { get; set; }
        [Required(AllowEmptyStrings = false, ErrorMessage = "请输入密码")]
        [StringLength(32, MinimumLength = 6, ErrorMessage = "密码需要大于6位")]//字段内容长度限制
        public string Password { get; set; }
        [Required(AllowEmptyStrings = false, ErrorMessage = "请输入昵称")]
        public string NickName { get; set; }
    }
}
